package com.qd.common.panda.domain.entity.shop.product;

import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 商品信息
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class ProductDTO extends BaseQuery {

    /**
     * 主键
     */
    @NotBlank(message = "商品编号不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "商品编号长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String productCode;
    /**
     * 名称
     */
    @NotBlank(message = "商品名称不能为空", groups = DefaultGroup.class)
    @Size(max = 100, message = "商品名称长度不能超过{max}位", groups = DefaultGroup.class)
    private String name;
    /**
     * 商品单价
     */
    @NotNull(message = "商品单价不能为空", groups = DefaultGroup.class)
    private BigDecimal price;
    /**
     * 商品单价显示
     */
    private String priceDisplay;
    /**
     * 库存数量
     */
    private Integer stock;
    /**
     * 商品封面图片
     */
    @NotBlank(message = "商品封面图片不能为空", groups = DefaultGroup.class)
    @Size(max = 200, message = "商品封面图片长度不能超过{max}位", groups = DefaultGroup.class)
    private String picUrl;
    /**
     * 上架时间
     */
    private LocalDateTime addTime;
    /**
     * 更新时间
     */
    private LocalDateTime updateTime;
    /**
     * 商品状态:0上架1下架
     */
    @NotNull(message = "商品状态不能为空", groups = DefaultGroup.class)
    private Integer state;
    /**
     * 厂家
     */
    @Size(max = 50, message = "厂家长度不能超过{max}位", groups = DefaultGroup.class)
    private String factory;
    /**
     * 商品介绍
     */
    @NotBlank(message = "商品详情介绍不能为空", groups = DefaultGroup.class)
    private String detail;
    /**
     * 商品图片
     */
    private List<ProductImgDTO> imgList;

    @Override
    public void freeData() {
        this.productCode = null;
        this.name = null;
        this.price = null;
        this.stock = null;
        this.picUrl = null;
        this.addTime = null;
        this.updateTime = null;
        this.state = null;
        this.factory = null;
        this.priceDisplay = null;
        this.detail = null;
        Optional.ofNullable(imgList).ifPresent(List::clear);
        super.freeData();
    }
}
